package com.hshx.controller;

//import com.hshx.pojo.Agency;
//import com.hshx.service.AgencyService;
import com.hshx.util.RedisUtil1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@CrossOrigin
@RequestMapping("/workService")
@RestController
public class AgencyController {
    @Resource
    private RedisUtil1 redisUtil1;
//    @Autowired
//    private AgencyService agencyService;
//
//    /**
//     * 新增一个代办
//     * @param agency
//     * @return
//     */
//    @RequestMapping("/addAgency")
//    public boolean addAgency(@SpringQueryMap Agency agency){
//        return agencyService.save(agency);
//    }
//
//    /**
//     * 从数据库中移除一条代办记录
//     * @param agencyId
//     * @return
//     */
//    @RequestMapping("/removeAgency")
//    public boolean removeAgency(int agencyId){
//        return agencyService.removeById(agencyId);
//    }
//
//    /**
//     * 对某条代办记录进行修改
//     * @param agency
//     * @return
//     */
//    @RequestMapping("/updateAgency")
//    public boolean updateAgency(@SpringQueryMap Agency agency){
//        return agencyService.updateById(agency);
//    }
//
//    /**
//     * 获取所有的代办信息
//     * @return
//     */
//    @RequestMapping("/getAllAgency")
//    public List<Agency> getAllAgency(){
//        return agencyService.list();
//    }
//
//    /**
//     * 得到某条代办信息
//     * @param agencyId
//     * @return
//     */
//    @RequestMapping("/getAgencyOne")
//    public Agency getAgencyOne(int agencyId){
//        return agencyService.getById(agencyId);
//    }

    /**
     * 添加一条通知信息
     * @param info
     * @return
     */
    @RequestMapping("/addAgency2")
    public boolean addAgency2(String info){
        redisUtil1.lPushTime("string",info,3*24*60);
        NoticeWebsocket.sendMessage(info);
        return true;
    }

    /**
     *得到所有的通知信息
     * @return
     */
    @RequestMapping("/getAgency")
    public List<String> getAgency(){
        return redisUtil1.lRange("string",0,-1).stream().map(o->((String)o)).collect(Collectors.toList());
    }
}
